import 'package:flutter/material.dart';
import 'package:flutter_1/utils/style.dart';

/// 下拉框
class PopupMenuButtonWidget {
  static Widget popupMenu(String selectedRole,
      List<PopupMenuEntry<String>> list, Function(String)? onSelected) {
    return PopupMenuButton<String>(
      color: Style.c_8cd5ff,
      initialValue: selectedRole,
      itemBuilder: (BuildContext context) {
        return list;
      },
      onSelected: onSelected,
      offset: const Offset(0, 50),
      constraints: const BoxConstraints(
        maxHeight: 100,
      ),
      tooltip: '', // 禁用默认的悬停提示
      child: Container(
        padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 13),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Text(
              selectedRole, // 显示当前选中的角色
              style: const TextStyle(color: Colors.black, fontSize: 16),
            ),
            const Icon(
              Icons.arrow_drop_down,
              color: Colors.white,
            )
          ],
        ),
      ),
    );
  }
}
